﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_Task 的摘要说明。
    /// </summary>
    public class TaskManage
    {
        private static readonly TaskDal MyDAL = new TaskDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result Add(Task model)
        {
            Result res = new Result();
            if (model.TaskName.Length == 0)
            {
                res.Errors = "“任务别名”不能为空！";
                return res;
            }

            if (model.Id == 0)
            {
                MyDAL.Add(model);
            }
            else
            {
                MyDAL.Edit(model);
            }
            return res;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="IDs"></param>
        /// <returns></returns>
        public Result Delete(string IDs)
        {
            Result res = new Result();
            if (string.IsNullOrEmpty(IDs))
            {
                res.Errors = "至少选择一项。";
            }
            else
            {
                MyDAL.Delete(MyConvert.ConvertToArr(IDs));
            }
            return res;
        }

        #endregion

        #region 加载数据

        /// <summary>
        /// 加载数据
        /// </summary>
        public Task GetInfo(string ID)
        {
            return MyDAL.GetInfo(int.Parse(ID));
        }

        #endregion

        /// <summary>
        /// 任务列表
        /// </summary>
        /// <returns></returns>
        public IList<Task> GetUsedList()
        {
            return MyDAL.GetUsedList();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="GV_List"></param>
        public void BindList(System.Web.UI.WebControls.BaseDataBoundControl GV_List)
        {
            GV_List.DataSource = MyDAL.DataList();
            GV_List.DataBind();
        }

        /// <summary>
        /// 更新最新执行的时间
        /// </summary>
        /// <returns></returns>
        public void UpdateLastRunTime(int ID)
        {
            MyDAL.UpdateLastRunTime(ID);
        }
    }
}